Prev Next |
This section is dedicated to best programming practices, speeding up Sitecore installation and debugging in Sitecore.
1. Programming Practices
Data Structuring can influence the performance. If the logic for home page news articles is to present the latest three, the logic of looking for articles structured as /year/month/day/article is faster than sorting a large number of articles stored directly under /news.
1.1. Speeding up Sitecore Development Installation
There are a number of options to speed up the Sitecore development installation:
-
Disable the indexes.
Indexes are responsible for the search bar in Sitecore taskbar. If you can work without it, then comment out the <indexes> section inside the database section in web.config (that is most probably /databases/master/indexes). The search will be disabled, along with index updates on each item create/update/delete operation.
- Switch your site to the 'live' mode. Live mode completely eliminates the need for publishing, which can be annoying in development scenarios, by taking all items directly from the content authoring database. To activate this go to your website in <sites> section of web.config (the site is called 'website' by default) and change database="web" to database="master". This is the way Sitecore client site works with the core database. Naturally, by switching the publishing off you also lose the publishing restrictions, that is 'do not publish/publish date' features.
1.2. Link Database
Sometimes it is required to get all Items in the database based on a given template. Iterating through the entire database may be a very expensive operation though.
However in this particular case, we can resort to the Link database. Link database is used by Sitecore to resolve all the linking issues - what referrers and what references the Item has. And if an item is based on a template, it also counts as a reference from the item to the template. The solution then is very simple: get all the referrers for a given template item.
Below you can see how Link Database is used in the RSS module architecture:
private static Item[] GetFeedsInDatabase(Database database, Language language)
{
TemplateItem feedTemplate = database.Templates[Constants.FeedTemplateID];
if (feedTemplate == null)
{
return null;
}
// Get all items refering to the feed template
ItemLink[] links = Globals.LinkDatabase.GetReferers(feedTemplate.InnerItem);
if (links == null)
{
return null;
}
ArrayList result = new ArrayList(links.Length);
// and filter the referers - we dont need to include masters
foreach(ItemLink link in links)
{
if (link.SourceDatabaseName == database.Name)
{
Item item = database.Items[link.SourceItemID, language];
if ((item != null) && (IsMaster(item) == false))
{
result.Add(item);
}
}
}
return (Item[])result.ToArray(typeof(Item));
}
See also:
2. Optimize VS 2005
If you are finding that Visual Studio 2005 if running slowly you can take these steps to improve the speed of your IDE. Here are the tips:
- Disable Start Page.
Tools » Options » Environment » Startup, Change At startup setting to Show empty environment.
- Disable the splash screen.
- Open the properties of Visual Studio 2005 shortcut. Add the parameter /nosplash to the target.
For example: "C:\Program Files\Microsoft Visual Studio 2005\Common7\IDE\devenv.exe" /nosplash - Close all unnecessary panels and tabs to prevent them from appearing when the IDE loads.
Then optimize your environment itself:
- Install Visual Studio 2005 SP1
- Turn off animations.
Tools » Options » Environment, uncheck Animate environment tools.
These and other useful features for optimising VS2005 were listed from an article published on a Sitecore blog recently. to see the posting click on the following link.
http://sitecore.alexiasoft.nl/2007/10/25/increasing-productivity-with-visual-studio-2005/
3. Optimize XSL
You should avoid using the descendant axes (//, etc.).
Because of a memory leak in the 1.1 .NET framework (http://support.microsoft.com/default.html?scid=KB;EN-US;Q316775) which can lead to increased CPU usage, implement .NET extensions instead of script embedded in the XSL code with msxml:script. .NET 2.0 may correct this issue. Implementing XSL Extensions is described at Creating Sitecore Extension Function.
4. Convert Underperforming XSL Renderings to .NET
Certain operations can be completed much more efficiently in .NET than in XSL. Use Sitecore’s browser-based debugger to identify poorly performing code for migration to pure .NET.
Invoking XSL may be more expensive in .NET than executing native .NET code. If possible, certain XSL renderings, especially those which consume a great deal of resources or can only be cached under limited conditions should be converted to .NET method renderings, sublayouts or web controls. Expensive XSL code can be converted to .NET extension controls and functions.
5. Static HTML Generation
Static generation should only be considered as a last resort as it defeats much of the value of implementing Sitecore.
6. Debugging
In addition to debuggers such as the one provided with Microsoft Visual Studio .NET, Sitecore provides a browser-based debugger which can be activated in Layout Studio and by choosing Start from the Debug menu, through http://server?sc=debug=1 or by creating a menu item in the core database such as through the debug package available from http://groups.yahoo.com/group/sitecore/files. Use Sitecore’s debugger to determine why pages are not rendering correctly and which rendering components are consuming inordinate resources. Use the Microsoft Visual Studio .NET debugger for line-level debugging. See http://sdn.sitecore.net/SDN5/Articles/API/Debugging%20Your%20Sitecore%20Code.html for specifics on debugging with Sitecore.
6.1. Accessing Sitecore Debugging More Easily
The Visual Studio .NET debugger is great for debugging .NET at the code level, but Sitecore’s browser-based debugger is often useful for performance analysis and high-level investigation such as looking at the output of an entire page or individual rendering. The debugger requires authentication as an administrator and provides some settings through /web.config (search for “debug”). There are at least two ways to access the debugger:
- Choose Start from the Debug menu in Layout Editor
- Access http://server?sc_debug=1 after authenticating
To add a Debug button to the bottom of the Sitecore menu, install the package or follow these steps:
- Log in to the Desktop as an administrator
- Switch to the Core Database using the icon in the lower right corner
- Open Content Editor
- Navigate to Documents and settings, All users, Start menu, Bottom
- Create a new Toolbutton
- In the Data Section
- Set Click to "system:debug"
- Set Header to "Debug"
- Set Icon to "Software/24x24/bug_red.png"
- Set ID to "Debug"
- Set Tool tip to "Debug"
- In the Appearance Section
- Set Icon to "Software/24x24/bug_red.png".
- In the Security Section
- Deny Everyone Read permission (it should only be exposed to administrators)
- In the Data Section
- Switch back to the Master Database
Refresh the desktop and a Debug item should appear at the bottom of the Sitecore menu.
You can download a ready-made package which adds a Debug button into Sitecore menu here .
Prev Next